package dbcTools.operationSql;

import java.util.ArrayList;

import dbcTools.PSSet.PSSet;
import dbcTools.base.StrSeparatorStrs;

public class Update extends OperationSql {
	private StrSeparatorStrs setSql;
	
	private ArrayList<PSSet> psSets;//用于存储？中的值的类型
	private ArrayList<Object> values;//用于存储？中的值，下标与valueTypes一一对应

	public Update(String tableName, ArrayList<PSSet> psSets, ArrayList<Object> values) {
		super(tableName);
		// TODO Auto-generated constructor stub
		this.setSql = new StrSeparatorStrs(",");
		this.psSets = psSets;
		this.values = values;
	}
	public void setPSSetAndValues(ArrayList<PSSet> psSets, ArrayList<Object> values) {
		this.psSets = psSets;
		this.values = values;
	}
	public void subUpdate(String setSql) {
		this.setSql.link(setSql);
	}

	public void update(String field, PSSet psSet, Object value) {
		setSql.link(field + " = ?");
		
		psSets.add(psSet);
		values.add(value);
	}
	
	public void clearSql() {
		setSql.clearStrSeparatorStrs();
	}
	
	@Override
	public String getSql() {
		// TODO Auto-generated method stub
		return "UPDATE " + tableName + " SET " + setSql.getSql();
	}
}
